<?php
require_once('../practice/db.php');
$offset = 2;
$page_num = isset($_GET['page']) ? $_GET['page'] : 1;
$limit = ($page_num-1)*$offset;

$total_records = countAll('uploaded_images');
$number_of_pages = ceil($total_records/$offset);

///////////// SELECT USERS /////
$allImages = findAll('uploaded_images',$where='', "LIMIT $limit,$offset");
////////////////////////////
//var_dump($allImages);

?>
<link href="css/form.css" rel="stylesheet" type="text/css" />

<table width="80%" border="1" cellpadding="5" cellspacing="0">
  <thead>
    <tr>
      <th>#</th>
      <th>Title</th>
      <th>Image</th>
      <th>Uploaded Date</th>
    </tr>
  </thead>
  <tbody>
<?php
$i = 1;
while ($images = mysql_fetch_assoc($allImages))
{
  $color = (($i++ % 2)==0)?'lightgreen':'lightblue';
?>
    <tr style="background-color:<?=$color?>">
      <td><a href="update_image.php?id=<?=$images['id']?>"><?=$images['id']?></a></td>
      <td><?=$images['title']?></td>
      <td><img src="uploads/<?=$images['path']?>" width="120" height="90"></td>
      <td><?=date('d-M-Y h:i:s a l',strtotime($images['uploaded_date']))?></td>
    </tr>
<?php
 pr($images);
}
?>
  </tbody>
</table>

<table  border="1" cellpadding="0" cellspacing="0" width="80%" >

    <tr>
<?php for($i=1 ; $i<= $number_of_pages ; $i++) {
  if($i == $page_num){
?>
<td align="center" style="color:red;font-size:30px;"><?=$i?></td>
<?php
  } else {
  ?>
      <td align="center"><a href="<?=$_SERVER['PHP_SELF']?>?page=<?=$i?>"><?=$i?></a></td>
<?php
  }//end else
}?>
    </tr>

</table>
